<template>
  <div class="login-page">
  <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
    <img src="../assets/text_login_top.png"/>
    <div class="login-title"><div>账户登录</div></div>
    <div class="login-form">
    <el-form-item prop="account">
      <el-input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="账号"></el-input>
    </el-form-item>
    <el-form-item prop="checkPass">
      <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
      <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
    </el-form-item>
    </div>
  </el-form>
    <div class="login-foot">2016-2020©北京新大陆时代教育科技有限公司</div>
  </div>
</template>

<script>
  import { clientLogin, getClientUser } from '@/api/api'
  // import NProgress from 'nprogress'
  export default {
    data () {
      return {
        logining: false,
        ruleForm2: {
          account: '',
          checkPass: ''
        },
        rules2: {
          account: [
            { required: true, message: '请输入账号', trigger: 'blur' }
            // { validator: validaePass }
          ],
          checkPass: [
            { required: true, message: '请输入密码', trigger: 'blur' }
            // { validator: validaePass2 }
          ]
        },
        checked: true
      }
    },
    created () {
      this.initData()
    },
    methods: {
      handleSubmit2 (ev) {
        let loginParams = { username: this.ruleForm2.account, password: this.ruleForm2.checkPass }
        clientLogin(loginParams).then(data => {
          if (data.status === 200) {
            alert('登录成功')
            if (data.data === 'teacher') {
              this.$router.push({path: '/manage/home'})
            } else {
              this.$router.push({path: '/platform/myTask'})
            }
          } else {
            alert(data.data)
          }
//          if (this.ruleForm2.account === 'admin') {
//            this.$router.push({path: '/manage/home'})
//          } else {
//            this.$router.push({path: '/platform/myCenter'})
//          }
        })
      },
      initData () {
        getClientUser().then(res => {
          if (res.status === 200) {
            this.$router.push({path: '/platform/myTask'})
          }
        })
      }
    }
  }

</script>

<style scoped lang="less">
  .login-page{
    background: url('../assets/bg_new.png') no-repeat;
    background-size: cover;
    height: 100%;
    width: 100%;
    text-align: center;
  }
  .demo-ruleForm{
    width: 464px;
    float: right;
    padding-top: 200px;
    padding-right: 100px;
    .login-title {
      height: 40px;
      margin-top: 10px;
      text-align: center;
      color: white;
      font-size: 20px;
      border-top-left-radius: 10px;
      border-top-right-radius: 10px;
      background: #4ac1ff;
      div {
        padding-top: 7px;
      }
    }
    .login-form {
      height: 188px;
      padding-top: 40px;
      opacity: 0.8;
      background: white;
      .el-form-item {
        width: 340px;
        margin-left: 62px;
      }
    }
  }
  .login-foot {
    background: white;
    height: 30px;
    line-height: 30px;
    font-size: 12px;
    width: 100%;
    position: fixed;
    bottom: 0;
    /*text-align: right;*/
    color: grey;
    vertical-align: middle;
 }
</style>
